package binaryTreeNode;

public class SearchInsert {
    public static void main(String[] args) {
        int[] nums={1,3,5,6};
        int target=2;
        System.out.println(searchInsert(nums,target));
    }
    public static int searchInsert(int[] nums, int target) {
        int l = 0, r = nums.length - 1, mid=-1;
        while (l <= r) {
            mid = (r + l) / 2;
            if (nums[mid] == target)
                return mid;
            else if (nums[mid] < target)
                l = mid + 1;
            else
                r = mid - 1;
        }
        return l+1;

    }

}
